// pages/my/my.js
import {
  Enum
} from "../../utils/enum.js"
import {
  Address
} from "../../utils/address.js"
var address = new Address();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    authorized: false,
    defaultAvatar: "/icon/user-avatar.jpg",
    defaultName: "行万里路",
    userInfo: {},
    userAddress: {},
    constRecycleOrder: Enum.orderType.recycleOrder,
    constBuyOrder: Enum.orderType.buyOrder
  },

  /**
   * 生命周期函数--监听页面加载
   */

  toMoney() {
    wx.navigateTo({
      url: '/pages/money/money',
    })
  },

  getUserInfo(event) {
    if (event.detail.userInfo) {
      this.setData({
        authorized: true,
        userInfo: event.detail.userInfo
      })
    }
  },

  getSellAddress() {
    var text = '广东省广州市番禺区小谷围广外生活区 book11收 15912345678'
    wx.showModal({
      title: 'Book11收货地址',
      content: text,
      success(res) {
        if (res.confirm) {
          wx.setClipboardData({
            data: text
          })
        }
      }
    })
  },

  setAddress() {
    address.chooseAddress(
      wx.chooseAddress({
        // 更新地址
        success: (res) => {
          // 更新数据库的地址信息
          address.updateDbAddress(res)
        }
      })
    )
  },

  toOrderlist(event) {
    // 跳转到 我的订单  卖书  买书
    wx.navigateTo({
      url: '/pages/order-list/order-list?orderType=' + event.currentTarget.dataset.type
    })
  }
})